//
//  YZMTradeCell.m
//  YZMicroStock
//
//  Created by Lv.Dongdong on 16/11/4.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMTradeCell.h"

@interface YZMTradeCell()

@property (nonatomic, strong) UIImageView *typeIV;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *stockLabel;
@property (nonatomic, strong) UILabel *stockCountLB;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *profitLB;

@end


@implementation YZMTradeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createObjects];
        self.rightMargin = 10.0;
        self.leftMargin = 10.0;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return self;
}

- (void)createObjects{
    
    WS(ws)
    self.typeIV = [UIImageView new];
    [self.contentView addSubview:self.typeIV];
    [self.typeIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(ws.contentView).offset(25);
        make.width.height.mas_equalTo(27);
        make.centerY.equalTo(ws.contentView);
    }];
    
    UIView *stockView = [[UIView alloc] init];
    [self.contentView addSubview:stockView];
    [stockView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.centerY.equalTo(ws.contentView);
    }];
    
    self.stockLabel = [YZMAppStyle labelWithMediumWhite];
    [stockView addSubview:self.stockLabel];
    [self.stockLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.centerX.equalTo(stockView);
        make.right.lessThanOrEqualTo(stockView);
    }];
    
    self.stockCountLB = [YZMAppStyle labelWithSmallLightGray];
    [stockView addSubview:self.stockCountLB];
    [self.stockCountLB mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(ws.stockLabel);
        make.bottom.right.lessThanOrEqualTo(stockView);
        make.top.equalTo(ws.stockLabel.mas_bottom).offset(3);
    }];
    
    UIView *helperView = [UIView new];
    [self.contentView addSubview:helperView];
    [helperView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(ws.typeIV.mas_right).offset(6);
        make.centerY.equalTo(ws.contentView);
        make.right.equalTo(stockView.mas_left).offset(-8);
    }];
    
    self.nameLabel = [YZMAppStyle labelWithMediumWhite];
    [helperView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.centerX.top.equalTo(helperView);
    }];
    
    self.timeLabel = [YZMAppStyle labelWithSmallLightGray];
    self.timeLabel.adjustsFontSizeToFitWidth = YES;
    self.timeLabel.minimumScaleFactor = 0.1;
    [helperView addSubview:ws.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.centerX.equalTo(ws.nameLabel);
        make.top.equalTo(ws.nameLabel.mas_bottom).offset(3);
        make.bottom.equalTo(helperView);
    }];
    
    UIView *rightView = [[UIView alloc] init];
    [self.contentView addSubview:rightView];
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(stockView.mas_right).offset(8);
        make.right.equalTo(ws.contentView).offset(-25);
        make.centerY.equalTo(ws.contentView);
    }];
    
    UILabel *distributionLB = [YZMAppStyle labelWithMediumWhite];
    distributionLB.text = @"盈利分配";
    [rightView addSubview:distributionLB];
    [distributionLB mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.right.equalTo(rightView);
    }];
    
    self.profitLB = [YZMAppStyle labelWithSmallYellow];
    [rightView addSubview:self.profitLB];
    [self.profitLB mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(distributionLB);
        make.top.equalTo(distributionLB.mas_bottom).offset(3);
        make.bottom.right.equalTo(rightView);
    }];

}

-(void)setModel:(YZMHomeUsersModel *)model
{
    self.nameLabel.text = model.userName;
    self.stockLabel.text = model.stockName;
    self.stockCountLB.text = [NSString stringWithFormat:@"%d股",model.volumeOrder ];
    self.timeLabel.text = @"1小时前";
    self.profitLB.text = [NSString stringWithFormat:@"%.2f",model.profitTotal];
}


-(void)setimagewithimageName:(NSString *)imageName
{
    self.typeIV.image = [UIImage imageNamed:imageName];
}


@end
